package com.cnoja.jmsncn.kernel;

import com.cnoja.jmsncn.inf.ICommander;
import com.cnoja.jmsncn.inf.IMessenger;
import com.cnoja.jmsncn.inf.IState;
import com.cnoja.jmsncn.kernel.exceptions.MessengerException;
import com.cnoja.jmsncn.kernel.exceptions.MissingParameterException;
import com.cnoja.jmsncn.utils.text.StringUtils;

public abstract class AbstractMessenger implements IMessenger {
	
	private ICommander commander = null;
	private String userName = null;

	private IState state = IState.LOGIN_STATE;

	public IState getState() {
		return state;
	}

	public String getUserName() {
		return userName;
	}

	public String getPassword() {
		return password;
	}

	private String password = null;

	public AbstractMessenger(String userName, String password) {
		this.userName = userName;
		this.password = password;

	}

	public void validateName() throws MessengerException {
		if (StringUtils.isNullOrEmpty(this.getUserName())) {
			throw new MissingParameterException(
					"The user name must be provided!");
		}
	}

	public void validatePassword() throws MessengerException {
		if (StringUtils.isNullOrEmpty(this.getPassword())) {
			throw new MissingParameterException(
					"The password must be provided!");
		}
	}
	
	
	public void setCommander(ICommander commander) {
		this.commander = commander;
		
	}
}
